import Vue from 'vue'
import VueRouter from 'vue-router'

const Login = () => import( /* webpackChunkName: "login_home_welcome" */ '@/views/Login.vue')
const Home = () => import( /* webpackChunkName: "login_home_welcome" */ '@/views/Home.vue')
const Welcome = () => import( /* webpackChunkName: "login_home_welcome" */ '@/views/Welcome.vue')
// import Login from '@/views/Login.vue'
// import Home from '@/views/Home.vue'
// import Welcome from '@/views/Welcome.vue'
const Users = () => import( /* webpackChunkName: "ueses_roles_rights" */ '@/views/Users.vue')
const Roles = () => import( /* webpackChunkName: "ueses_roles_rights" */ '@/views/Roles.vue')
const Rights = () => import( /* webpackChunkName: "ueses_roles_rights" */ '@/views/Rights.vue')

// import Users from '@/views/Users.vue'
// import Roles from '@/views/Roles.vue'
// import Rights from '@/views/Rights.vue'
const Reports = () => import( /* webpackChunkName: "report_parmas_order" */ '@/views/Reports.vue')
const Params = () => import( /* webpackChunkName: "report_parmas_order" */ '@/views/Params.vue')
const Orders = () => import( /* webpackChunkName: "report_parmas_order" */ '@/views/Orders.vue')

// import Reports from '@/views/Reports.vue'
// import Params from '@/views/Params.vue'
// import Orders from '@/views/Orders.vue'
const Goods = () => import( /* webpackChunkName: "goods_categories_addgoods" */ '@/views/Goods.vue')
const Categories = () => import( /* webpackChunkName: "goods_categories_addgoods" */ '@/views/Categories.vue')
const AddGoods = () => import( /* webpackChunkName: "goods_categories_addgoods" */ '@/views/AddGoods.vue')

// import Goods from '@/views/Goods.vue'
// import Categories from '@/views/Categories.vue'
// import AddGoods from '@/views/AddGoods.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [{
        path: '/welcome',
        component: Welcome
      },
      {
        path: '/users',
        component: Users
      },
      {
        path: '/roles',
        component: Roles
      },
      {
        path: '/rights',
        component: Rights
      },
      {
        path: '/reports',
        component: Reports
      },
      {
        path: '/params',
        component: Params
      },
      {
        path: '/orders',
        component: Orders
      },
      {
        path: '/goods',
        component: Goods
      },
      {
        path: '/categories',
        component: Categories
      },
      {
        path: '/add',
        component: AddGoods
      }
    ]
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next();
  const tokenStr = sessionStorage.getItem('token');
  if (!tokenStr) return next('/login');
  next();
})
export default router